package com.mmy.controller.hotel;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mmy.domain.hotel.THotelRoom;
import com.mmy.domain.hotel.VHotelBase;
import com.mmy.domain.hotel.VHotelPlan;
import com.mmy.service.impl.hotel.THotelBaseServiceImpl;
import com.mmy.service.impl.hotel.THotelRoomServiceImpl;
import com.mmy.service.impl.hotel.VHotelBaseServiceImpl;
import com.mmy.service.impl.hotel.VHotelPlanServiceImpl;

@Controller
public class VHotelPlanController {
	@Autowired
	VHotelPlanServiceImpl vHotelPlanServiceImpl;
	@Autowired
	THotelBaseServiceImpl tHotelBaseServiceImpl;
	@Autowired
	VHotelBaseServiceImpl vHotelBaseServiceImpl;
	@Autowired
	THotelRoomServiceImpl tHotelRoomServiceImpl;

	/**
	 * 函数功能说明： 跳转
	 *
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 shangzl
	 * @date 创建日期2020-08-11
	 */
	@RequestMapping(value = "/hotelplan")
	public String ToRestaurantPlan(Model model) {
		try {

			List<VHotelPlan> lstHotelPlan = vHotelPlanServiceImpl.findAll();
			model.addAttribute("newHotelPlanList", lstHotelPlan);
			/* 查询所有的酒店 */
			List<VHotelBase> lstHotelBase = vHotelBaseServiceImpl.findALL();
			model.addAttribute("newLstHotelBase", lstHotelBase);
			/* 查询所有的酒店房间 */
			List<THotelRoom> lstHotelRoom = tHotelRoomServiceImpl.findALL();
			model.addAttribute("newLstHotelRoom", lstHotelRoom);

			return "webbackground/hotelmanagement/hotelplan";
		} catch (Exception e) {

		}
		return null;

	}

	/**
	 * 函数功能说明： 修改酒店计划
	 *
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 shangzl
	 * @date 创建日期
	 */

	@RequestMapping(value = "/toupdatehotelplan")
	public String toUpdateRestaurantPlan(HttpServletRequest request, Model model) {

		int iPlanID = Integer.parseInt(request.getParameter("iPlanID"));

		VHotelPlan vHotelPlan = vHotelPlanServiceImpl.findByPlanID(iPlanID);
		model.addAttribute("newVHotelPlan", vHotelPlan);
		/* 查询所有的酒店 */
		List<VHotelBase> lstHotelBase = vHotelBaseServiceImpl.findALL();
		model.addAttribute("newLstHotelBase", lstHotelBase);
		/* 查询所有的酒店房间 */
		List<THotelRoom> lstHotelRoom = tHotelRoomServiceImpl.findALL();
		model.addAttribute("newLstHotelRoom", lstHotelRoom);

		return "webbackground/hotelmanagement/updatehotelplan";

	}

	/**
	 * 函数功能说明： 查询餐馆计划信息
	 *
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 shangzl
	 * @date 创建日期 2020-08-06
	 */
	@RequestMapping(value = "/searchhotelplan")
	public String FindHotelPlan(HttpServletRequest request, Model model) {
		String strHotelID = request.getParameter("HotelID");
		String strRoomID = request.getParameter("RoomID");
		List<VHotelPlan> lstHotelPlan = new ArrayList<VHotelPlan>();
		if (strHotelID == "" && strRoomID == "") {
			lstHotelPlan = vHotelPlanServiceImpl.findAll();

		} else if (strHotelID != "" && strRoomID == "") {
			List<THotelRoom> lstHotelRoom = tHotelRoomServiceImpl.findByHotelID(Integer.parseInt(strHotelID));
			List<Integer> lstRoomID = new ArrayList<>();
			int RoomID = 0;
			for (THotelRoom Room : lstHotelRoom) {
				RoomID = Room.getRoomID();
				lstRoomID.add(RoomID);
			}
			lstHotelPlan = vHotelPlanServiceImpl.findByRoomIDs(lstRoomID);

		}
		model.addAttribute("newHotelPlanList", lstHotelPlan);
		/* 查询所有的酒店 */
		List<VHotelBase> lstHotelBase = vHotelBaseServiceImpl.findALL();
		model.addAttribute("newLstHotelBase", lstHotelBase);
		/* 查询所有的酒店房间 */
		List<THotelRoom> lstHotelRoom = tHotelRoomServiceImpl.findALL();
		model.addAttribute("newLstHotelRoom", lstHotelRoom);
		return "webbackground/restaurantmanagement/restaurantplan";

	}

	/* 跳转查看计划详情 */
	@RequestMapping(value = "/hotelplaninfo")
	public String ToHotelPlanInfo(HttpServletRequest request, Model model) {

		int iPlanID = Integer.parseInt(request.getParameter("iPlanID"));

		VHotelPlan vHotelPlan = vHotelPlanServiceImpl.findByPlanID(iPlanID);
		model.addAttribute("newVHotelPlan", vHotelPlan);

		return "webbackground/hotelmanagement/hotelplaninfo";
	}
}
